package com.wanxi.util;

import java.util.Scanner;

public class MyTest {
    static int[] arr = new int[5];

    public static void main(String[] args) {
        setArray();
        getMaxNum();
        getMinNum();
    }

    /**
     * 创建一个5个长度的随机数组
     */
    private static void setArray() {
        Scanner scanner = new Scanner(System.in);
//        int[] arr = {1, 1, 1, 1, 1};

        for (int i = 0; i < arr.length; i++) {
            System.out.println("请输入第" + (i + 1) + "个数");
            arr[i] = scanner.nextInt();
        }
    }

    /**
     * 求数组的最大值
     */
    private static void getMaxNum() {
        int max = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (max < arr[i]) {
                max = arr[i];
            }
        }
        System.out.println();
    }

    /**
     * 求数组的最小值
     */
    private static void getMinNum() {
        int min = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (min > arr[i]) {
                min = arr[i];
            }
        }
        System.out.println(min);
    }
}
